import Vue from "vue";
import Router from "vue-router";
import Home from "@/components/Home";

import Streamer from "@/components/page/streamer/Streamer";
import Login from "@/components/page/user/Login";

Vue.use(Router);

let router = new Router({
  routes: [
    {
      path: "/",
      name: "Home",
      component: Home,
      children: [
        {
          path: "/",
          name: "streamer",
          component: Streamer
        },
      ]
    },
    {
      path: "/login",
      name: "Login",
      component: Login
    },
  ]
});

router.beforeEach((to, from, next) => {
  if (to.path !== "/login") {
    let _t = Vue.prototype.$cookies.get("_t");
    if (!_t) {
      next({ path: "/login" });
    } else {
      next();
    }
  } else {
    next();
  }
});

export default router;
